package com.qing;


import java.util.Arrays;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import java.util.function.ToIntBiFunction;
import java.util.function.ToIntFunction;
import java.util.stream.Collectors;

public class Hello {
	public static void main(String[] args) {
			/**
			 * 假设你想要忽略大小写对一个由字符串组成的List排序
			 */
			List<String> strs= Arrays.asList("q","d","D","a","B");
			strs.sort((s1,s2)->s1.compareToIgnoreCase(s2));
			System.out.println(strs);
			System.out.println("-----------------------");

			List<String> strs2= Arrays.asList("q","d","D","a","B");
			strs2.sort(String::compareToIgnoreCase);
			System.out.println(strs2);
			/**
			 * 运行：
			 * [a, B, d, D, q]
			 * -----------------------
			 * [a, B, d, D, q]
			 */

		/**
		 * 将某个类型转换为Int类型
 		 */
		ToIntFunction<String> stringToInt=(String s)->Integer.parseInt(s);
		System.out.println(stringToInt.applyAsInt("123"));

		System.out.println("------------------------");
		ToIntFunction<String> stringToInt2=Integer::parseInt;
		System.out.println(stringToInt2.applyAsInt("123"));

		/**
		 * 运行
		 * 123
		 * ------------------------
		 * 123
		 */


		/**
		 * list是否存在某元素
		 */
//		BiPredicate<List<String>,String> contains=(list,element)->list.contains(element);
		BiPredicate<List<String>,String> contains=List::contains;
		List<String> list=Arrays.asList("A","B","D","M","e");
		Boolean existsD=contains.test(list,"D");
		Boolean existsF=contains.test(list,"f");
		System.out.println(existsD); //true
		System.out.println(existsF); //false


		List<Integer> integers= Arrays.asList(1,3,4,5,8,9,3,4,5,2,6,9,4);
		integers.stream().filter(a -> a % 2 == 0).distinct().forEach(System.out::println); // 4,8,2,6
	}
}
